package com.zsule.service.impl;

import java.util.List;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import com.zsule.entity.ECartItem;
import com.zsule.frameworks.mongodb.service.MongoAbstractService;
import com.zsule.service.ICartItemService;

@Service("ecartItemService")
public class CartItemServiceImpl extends MongoAbstractService<ECartItem> implements
		ICartItemService {

	

	@Override
	public ECartItem getMyItem(String goodsId,String userId) {
		return findOne(Criteria.where("goodsId").is(goodsId).and("userId").is(userId));
	}
	
	@Override
	public ECartItem getMyItem(String shopId,String goodsId,String userId) {
		return findOne(Criteria.where("goodsId").is(goodsId).and("userId").is(userId).and("shopId").is(shopId));
	}
	
	@Override
	public ECartItem getMyItem(ECartItem item) {
		return getMyItem(item.getShopId(),item.getGoodsId(),item.getUserId());
	}

	@Override
	public List<ECartItem> getItems(String userId) {
		return findList(Criteria.where("userId").is(userId));
	}

	@Override
	public List<ECartItem> getSubItems(String userId, String shopId) {
		return findList(Criteria.where("userId").is(userId).and("shopId").is(shopId));
	}
	public void updateCount(String id,int count){
		updateFirst(Criteria.where("id").is(id), new Update().set("goodsCount", count));
	}
	@Override
	public void addCount(String id) {
		updateCount(id,1);
	}
	@Override
	public void delCount(String id) {
		updateCount(id,-1);
	}
}
